/** *****************  JAVA头文件说明  ****************
 * file name  :  GoodsController.java
 * owner      :  dmm
 * copyright  :  UMPAY
 * description:  
 * modified   :  2016-11-4
 * *************************************************/

package com.busi.controller.activity;


import com.alibaba.fastjson.JSONObject;
import com.busi.model.Activity;
import com.busi.model.ActivityGoodsList;
import com.busi.model.Activitygoods;
import com.busi.model.Advert;
import com.busi.model.Advertinfo;
import com.busi.model.Goods;
import com.busi.util.HttpUtils;
import com.busi.util.PropertyUtil;
import com.jfinal.upload.UploadFile;
import com.zcurd.controller.BaseController;


/** ******************  类说明  *********************
 * class       :  AdvertisementController
 * @author     :  hs
 * @version    :  1.0  
 * description :  
 * @see        :                        
 * 
 * ************************************************/
public class ActivitController extends BaseController {	
	//private static final String UPLOAD_IMAGE_PAGE = "uploadimage/";
	//列表
	public void list() {
		render("list.html");
	}
	//增加页面
	public void addPage() {
		render("add.html");
	}
	//修改页面
	public void updatePage() {
		Activity activity = getBean(Activity.class,"");
		String body = gson.toJson(activity);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		//根据positionid查询广告数据
		String url = domain + "/emall/admin/activity/querylist";
		LOG.info("#updatePage() 请求:"+url);
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.debug("#updatePage() 响应:"+jsonString);
		Activity activity1 = gson.fromJson(jsonString, Activity.class);
		setAttr("activity", activity1);
		render("update.html");
	}
	
	//进入广告管理的修改页面
	public void updatecurationPage() {
		String id = getPara("id");
		Activitygoods activitygoods = getBean(Activitygoods.class,"");
		activitygoods.setId(id);
		String body = gson.toJson(activitygoods);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		//根据positionid,查询数据
		String url = domain + "/emall/admin/activitygoods/querylist";
		LOG.info("#updatecurationPage() 请求:"+url);
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.debug("#updatePage() 响应:"+jsonString);
		Activitygoods activitygoods1 = gson.fromJson(jsonString, Activitygoods.class);
		//setAttr("id", id);
		setAttr("activitygoods", activitygoods1);
		render("updateadc.html");
	}
	
	//管理页面
	public void adcurationPage() {
		String activityid = getPara("activityid");
		setAttr("activityid", activityid);
		render("adcuration.html");
	}
	
	
	//管理增加页面
	public void addcurationPage() {
		String activityid = getPara("activityid");
		setAttr("activityid", activityid);		
		render("addadc.html");
	}

	public void listData() {
		//根据商户id查商户的商品列表
		Activity activity = getBean(Activity.class,"");
		String body = gson.toJson(activity);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String url = domain + "/emall/admin/activity/queryactivity";
		String[][] headers = {{"Content-Type", "application/json"}};
		LOG.info("#listData() 请求报文:"+body);
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.debug("#listData 返回信息:"+jsonString);
		renderJson(jsonString==null?"":jsonString);
	}
	
	//广告信息查询
	public void listDataInfo() {
		Activitygoods activitygoods = getBean(Activitygoods.class,"");
		activitygoods.setActivityid(getPara("activityid"));
		String body = gson.toJson(activitygoods);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String url = domain + "/emall/admin/activitygoods/queryactivitygoods";
		String[][] headers = {{"Content-Type", "application/json"}};
		LOG.info("#listData() 请求报文:"+body);
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("#listData 返回信息:"+jsonString);
		renderJson(jsonString==null?"":jsonString);
	}
	
	//活动内容查询列表listDataInfoo1
	public void listDataInfoo1() {
		ActivityGoodsList goodsList = getBean(ActivityGoodsList.class,"");
		String body = gson.toJson(goodsList);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String url = domain + "/emall/admin/goods/querygoodslist";
		String[][] headers = {{"Content-Type", "application/json"}};
		LOG.info("#listData() 请求报文:"+body);
		String jsonString = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		LOG.info("#listData 返回信息:"+jsonString);
		renderJson(jsonString==null?"":jsonString);
	}
	//广告添加操作
	public void add(){
		String user_name = (String)getSessionUser().get("user_name");
		Activity activity = getBean(Activity.class,"");
		activity.setCreateuser(user_name);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		//添加广告
		String url = domain + "/emall/admin/activity/addactivity";
		String body = gson.toJson(activity);
		LOG.info("#add() 添加商品请求报文:"+body+",操作人："+user_name+",activity:"+activity);
		String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		JSONObject ret1 =(JSONObject) JSONObject.parse(ret);
		if("0000".equals(ret1.get("ret"))){
			LOG.info("#add() 添加商品成功,操作人："+user_name+",ret:"+ret);
			//renderText("success");
			renderSuccess();
		}else{
			LOG.info("#add() 添加商品失败,操作人："+user_name+",ret:"+ret);
			//renderText("fail");
			renderFailed(ret=="操作失败！"?"":ret);
		}
	}
	
	//广告信息增加
	public void addInfo(){
//		String goodsnameaa = getPara("goodsnameaa");
		String user_name = (String)getSessionUser().get("user_name");
		Activitygoods activitygoods = getBean(Activitygoods.class, "");
		String activityid = getPara("activityid");
		activitygoods.setActivityid(activityid);
		activitygoods.setCreateuser(user_name);
//		activitygoods.setGoodsname(goodsnameaa);
		renderFailed();
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		//添加广告
		String url = domain + "/emall/admin/activitygoods/addactivitygoods";
		String body = gson.toJson(activitygoods);
		LOG.info("#addInfo() 添加广告信息请求报文:"+body+",操作人："+user_name+",activitygoods:"+activitygoods);
		String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		JSONObject ret1 =(JSONObject) JSONObject.parse(ret);
		if("0000".equals(ret1.get("ret"))){
			LOG.info("addInfo() 添加商品成功,操作人："+user_name+",ret:"+ret);
			renderSuccess();
		}else{
			LOG.info("addInfo() 添加商品失败,操作人："+user_name+",ret:"+ret);
			renderFailed(ret=="操作失败！"?"":ret);
		}
	}
	
	
	//广告删除
	public void delete() {
		String activityid = getPara("activityid");
		LOG.info("#delete() 删除广告请求报文," + activityid);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String url = domain + "/emall/admin/activity/deletactivity/" + activityid;
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doGet(url, headers, 3, 5, "utf-8");
		JSONObject ret =(JSONObject) JSONObject.parse(jsonString);
		LOG.info("#delete() 删除广告响应报文," + jsonString);
		if("0000".equals(ret.get("ret"))){
			renderSuccess();
		}else{
			renderFailed(jsonString=="操作失败！"?"":jsonString);
		}
	}
	//广告信息删除
	public void deleteinfo() {
		String id = getPara("id");
		LOG.info("#deleteinfo() 删除广告信息请求报文," + id);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String url = domain + "/emall/admin/activitygoods/delactivitygoods/" + id;
		String[][] headers = {{"Content-Type", "application/json"}};
		String jsonString = HttpUtils.doGet(url, headers, 3, 5, "utf-8");
		JSONObject ret =(JSONObject) JSONObject.parse(jsonString);
		LOG.info("#deleteinfo() 删除广告信息响应报文," + jsonString);
		if("0000".equals(ret.get("ret"))){
			renderSuccess();
		}else{
			renderFailed(jsonString=="操作失败！"?"":jsonString);
		}
	}
	
	
	//广告编辑保存
	public void update() {
		String user_name = (String)getSessionUser().get("user_name");
		Activity activity = getBean(Activity.class, "");
		activity.setModuser(user_name);
		String domain = PropertyUtil.getStrValue("platform.domain", "");
		String[][] headers = {{"Content-Type", "application/json"}};
		//添加广告
		String url = domain + "/emall/admin/activity/notifyactivity";
		String body = gson.toJson(activity);
		LOG.info("#add() 修改商品请求报文:"+body+",操作人："+user_name+",activity:"+activity);
		String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
		JSONObject ret1 =(JSONObject) JSONObject.parse(ret);
		if("0000".equals(ret1.get("ret"))){
			LOG.info("#add() 修改商品成功,操作人："+user_name+",ret:"+ret);
			//renderText("success");
			renderSuccess();
		}else{
			LOG.info("#add() 修改商品失败,操作人："+user_name+",ret:"+ret);
			//renderText("fail");
			renderFailed(ret=="操作失败！"?"":ret);
		}
	}
	
	//广告编辑保存
		public void updateInfo() {
			/*//String deployPath = super.getDeployPath();
			UploadFile adpicture = getFile("adpicture");
			String fileName =null;
			if (adpicture!=null) {
				fileName = adpicture.getFileName();
			}
			//String ss = null;
			String user_name = (String)getSessionUser().get("user_name");
			 Advertinfo advertinfo = getBean(Advertinfo.class, "");
			 advertinfo.setModuser(user_name);
			 if (fileName!=null) {
				 advertinfo.setAdpicture("/upload/" + fileName);
			}
			String domain = PropertyUtil.getStrValue("platform.domain", "");
			String[][] headers = {{"Content-Type", "application/json"}};
			//添加广告
			String url = domain + "/emall/admin/advertinfo/notifyadvertinfo";
			String body = gson.toJson(advertinfo);
			LOG.info("#add() 修改商品请求报文:"+body+",操作人："+user_name+",advertinfo:"+advertinfo);
			String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
			JSONObject ret1 =(JSONObject) JSONObject.parse(ret);
			if("0000".equals(ret1.get("ret"))){
				LOG.info("#add() 修改商品成功,操作人："+user_name+",advertinfo:"+advertinfo);
				//renderText("success");
				renderSuccess();
			}else{
				LOG.info("#add() 修改商品失败,操作人："+user_name+",advertinfo:"+advertinfo);
				//renderText("fail");
				renderFailed(ret=="操作失败！"?"":ret);
			}
		}*/
//			String goodsnameaa = getPara("goodsnameaa");
			String user_name = (String)getSessionUser().get("user_name");
			Activitygoods activitygoods = getBean(Activitygoods.class, "");
			String activityid = getPara("activityid");
			activitygoods.setActivityid(activityid);
			activitygoods.setModuser(user_name);
//			activitygoods.setGoodsname(goodsnameaa);
			renderFailed();
			String domain = PropertyUtil.getStrValue("platform.domain", "");
			String[][] headers = {{"Content-Type", "application/json"}};
			//添加广告
			String url = domain + "/emall/admin/activitygoods/notifyactivitygoods";
			String body = gson.toJson(activitygoods);
			LOG.info("#updateInfo() 添加广告信息请求报文:"+body+",操作人："+user_name+",activitygoods:"+activitygoods);
			String ret = HttpUtils.doPost(url, body, headers, 3, 5, "utf-8");
			JSONObject ret1 =(JSONObject) JSONObject.parse(ret);
			if("0000".equals(ret1.get("ret"))){
				LOG.info("updateInfo() 添加商品成功,操作人："+user_name+",ret:"+ret);
				renderSuccess();
			}else{
				LOG.info("updateInfo() 添加商品失败,操作人："+user_name+",ret:"+ret);
				renderFailed(ret=="操作失败！"?"":ret);
			}		
		}
		
		
		
		
		
		
}
